package com.fast.alden.admin.scheduling;

import com.fast.alden.admin.service.SysApiResourceCacheService;
import com.fast.alden.admin.service.SysApiResourceService;
import com.fast.alden.admin.web.websocket.MessageCountWebSocketServer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务清单
 */
@Component
@Slf4j
public class ScheduledTask {
    @Resource
    private SysApiResourceService apiResourceService;
    @Resource
    private SysApiResourceCacheService apiResourceCacheService;
    @Resource
    private MessageCountWebSocketServer messageCountWebSocketServer;

    /**
     * 凌晨2点30分刷新API资源缓存
     */
    @Scheduled(cron = "0 30 2 * * *")
    public void refreshApiResourceCache() {
        apiResourceCacheService.flushApiResourceList();
        apiResourceService.list();
        log.info("刷新API资源缓存");
    }

    /**
     * 每5s推送一次消息提醒数量
     */
    @Scheduled(cron = "0/5 * * * * *")
    public void refreshMessageCount() {
        messageCountWebSocketServer.refreshCount();
    }
}
